﻿namespace WinFormsApp1
{
    internal static class Program
    {
        /// <summary>
        ///  The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            // To customize application configuration such as set high DPI settings or default font,
            // see https://aka.ms/applicationconfiguration.
            ApplicationConfiguration.Initialize();

            // 1. 显示登录窗体
            using (var loginForm = new LoginForm())
            {
                var loginResult = loginForm.ShowDialog();

                // 2. 如果登录成功，显示主窗体（LoggedInUser 可能为null，但不阻止进入主界面）
                if (loginResult == DialogResult.OK)
                {
                    try
                    {
                        Application.Run(new MainForm(loginForm.LoggedInUser));
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show($"启动主界面失败：{ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    // 登录失败或取消，正常结束进程
                    return;
                }
            }
        }
    }
}